import request from '@/utils/request';
import { commonProjectType, registerSource } from '@/common/baseUrl.js';
// import { user } from './../mock/mock.js';

// 首页获取服务包列表
export function getCity(data) {
  return request({
    url: `/cfg/provinceAndCity`,
    method: 'get'
  });
}
// 通过自定义code获取appid
export function getAppid(data) {
  return request({
    url: `/wx/ma/getAppId?code=${data}`,
    noAuth: true,
    method: 'get'
  });
}
// 小程序登录，把微信code和appid传给后台
export function login(data) {
  return request({
    url: `/wx/ma/login?appid=${data.appid}&jsCode=${data.jscode}`,
    method: 'get',
    noAuth: true,
    data
  });
}
// 传给后台用户信息
export function sendInfo(data) {
  return request({
    url: `/wx/ma/info`,
    method: 'post',
    noAuth: true,
    data
  });
}
// 发送手机号相关信息给后台
export function sendPhone(data) {
  return request({
    url: `/wx/ma/phone`,
    method: 'POST',
    noAuth: true,
    data
  });
}
// 使用unionId登录 POST
export function getToken(data) {
  return request({
    url: `/oauth/loginByUnionId`,
    method: 'post',
    noAuth: true,
    data
  });
}
// 通过patientId获取会员信息
export function getUserInfoByPatientId(patientId) {
  // return user(3);
  return request({
    url: `/patient/${patientId}`,
    method: 'get'
  });
}
// 新用户微信签约
export function bindPatients(data) {
  data.signSource = '8192';
  data.appid = wx.getStorageSync('appid') || undefined;
  data.unionId = wx.getStorageSync('unionid') || undefined;
  data.openId = wx.getStorageSync('openid') || undefined;
  return request({
    url: `/patients`,
    method: 'post',
    noqs: true,
    noAuth: true,
    data
  });
}
// 检查签约可用性，通过身份证号和手机号获取patientId
export function getPatientIdByIdCard(data) {
  return request({
    url: `/patients/available?phone=${data.phone}&idCard=${data.idCard}`,
    method: 'get',
    noAuth: true
  });
}
// 校验是否可通过实名认证
export function getRealNameResult(data) {
  return request({
    url: `/patients/${data.patientId}/patientCertification`,
    method: 'post',
    data
  });
}
// 校验用户是否可以上保险 insurance_order/verifyPatientInsuranceOrder
export function getCheckBuyServerResult(patientId) {
  return request({
    url: `/patient/${patientId}/insurance_order/inservice`,
    method: 'get'
  });
}
// 完善信息 perfectInformation
export function sendUserInfoForm(data) {
  return request({
    url: `/perfectInformation`,
    method: 'post',
    noqs: true,
    data
  });
}
// 获取标签列表
export function getTagsList() {
  return request({
    url: `/cfg/tags`,
    method: 'get'
  });
}
// 新增用户标签
export function bingPatientTag(data) {
  return request({
    url: `/patients/${data.patientId}/tags`,
    method: 'post',
    data
  });
}
// 查询疾病
export function getDiseasesList(name, skip, limit) {
  return request({
    url: `/cfg/enum/diseases?name=${name}&skip=${skip}&limit=${limit}`,
    method: 'get'
  });
}
export function getDiseasesHotList() {
  return request({
    url: `/cfg/enum/hotDiseases`,
    method: 'get'
  });
}
// 申领金
export function sendPublicGold(data) {
  return request({
    url: `/assistanceApply`,
    method: 'post',
    noqs: true,
    data
  });
}
// 申领金
export function getCanAssistanceApply(patientId) {
  return request({
    url: `/insurance_order/canAssistanceApply?patientId=${patientId}`,
    method: 'get'
  });
}
// 保险报查询
export function getServerPackInof(insurance_package_id) {
  return request({
    url: `/insurance_packages/${insurance_package_id}/products`,
    noAuth: true,
    method: 'get'
  });
}
// 根据服务包id查询已购买数量
export function getServerPackSaleNum(insurance_package_id) {
  return request({
    url: `/insurance_packages/${insurance_package_id}/stat`,
    method: 'get'
  });
}
// 查询文章详情
export function getArticleDetails(articleId) {
  return request({
    url: `/wcm/articles/${articleId}`,
    noAuth: true,
    method: 'get'
  });
}
// 项目4 服务包查询
export function getServerPack() {
  return request({
    url: `/insurance_packages?positions=&skip=0&limit=10&projectType=${commonProjectType}`,
    method: 'get'
  });
}
// 项目6 服务包查询
export function getServerPackSix(position) {
  return request({
    url: `/insurance_packages?positions=${position}&skip=0&limit=100&projectType=${commonProjectType}&wxCode=jksq-mini`,
    noAuth: true,
    method: 'get'
  });
}
// 选择省市区
export function getArea(data) {
  return request({
    url: `/cfg/enum/regions?provinceId=${data.provinceId}&cityId=${data.cityId}&areaId=${data.areaId}`,
    method: 'get'
  });
}
// 购买人历史记录
export function getFamilyMember(patientId) {
  return request({
    url: `/patients/${patientId}/familyMember`,
    method: 'get'
  });
}
// 购买人历史记录
export function addFamilyMember(data) {
  return request({
    url: `/patients/addFamilyMember`,
    method: 'post',
    data
  });
}
// 新增客户就诊记录
export function addMedical(data) {
  return request({
    url: `/patients/medical`,
    method: 'post',
    noqs: true,
    data
  });
}
// / idCardCheck
export function checkRealName(data) {
  return request({
    url: `/idCardCheck?idCard=${data.idCard}&name=${data.name}`,
    method: 'get'
  });
}

// 获取全部地址
export function alladd() {
  return request({
    url: `/cfg/allProvinces`,
    method: 'get'
  });
}

// 获取验证码
export function getMesCode(data) {
  return request({
    url: `/patient-sms-send`,
    method: 'post',
    data
  });
}
// 验证手机验证码
export function checkMesCode(data) {
  return request({
    url: `/patient-sms-verify`,
    method: 'post',
    data
  });
}
// /
export function getServicePackLink(packageId) {
  return request({
    url: `/insurance_package/${packageId}/specifications`,
    noAuth: true,
    method: 'get'
  });
}
// 创建个人服务单(v2)
export function createServiceOrder(data) {
  data.source = registerSource;
  return request({
    url: `/patients/insurance_orders/v2`,
    method: 'post',
    noqs: true,
    data
  });
}
// 查询会员服务单 GET /patients/{patientId}/insuranceOrder
export function getInsuranceOrder(patientId, payStates, insuredId) {
  return request({
    url: `/patients/${patientId}/insuranceOrder?payStatus=${payStates}&insuredId=${insuredId}`,
    method: 'get'
  });
}
// 解绑会员关系 DELETE /patients/{patientId}/familyMember?memberId=xxxx
export function deleteFamilyMember(patientId, memberId) {
  return request({
    url: `//patients/${patientId}/familyMember?memberId=${memberId}`,
    method: 'delete'
  });
}

export function getCurrentUserInfo() {
  // 如果用户已经登录，则获取用户信息，否则不用获取
  return request({
    url: '/users/currentUserInfo',
    method: 'get'
  });
}
